package com.domino.client.view.historicboard;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import com.domino.shared.Player;
import com.domino.shared.model.Board;
import com.domino.shared.model.Brick;
import com.domino.shared.model.Color;
import com.domino.shared.model.Point;
import com.domino.shared.model.SimpleBoard;

public class HistoricBoard implements Board {
	
	private Board board = null;
	private int size;
	
	public HistoricBoard(int size) {
		this.size = size;
	}

	public Board setRoundNumber(int round, Board currentBoard) {
		if (board==null) {
			board = new SimpleBoard(size);
		}
		if (round<board.getBricks().size()) {
			board = new SimpleBoard(size);
		}
		List<Brick> bricks = currentBoard.getBricks();
		for(int i=board.getBricks().size(); i<round && i<currentBoard.getBricks().size(); i++) {
			Brick brick = bricks.get(i);
			board.putBrick(brick);
		}
		return this;
	}

	@Override
	public Set<Point> getAvailblePoints(Color color) {
		return Collections.EMPTY_SET;
	}

	@Override
	public Color getColor(Point point) {
		return board.getColor(point);
	}

	@Override
	public int getColorCount(Color color) {
		return board.getColorCount(color);
	}

	@Override
	public void putBrick(Brick brick) {
		throw new UnsupportedOperationException("Tried to rewrite history");
	}

	public List<Brick> getBricks() {
		return board.getBricks();
	}

	@Override
	public int getRoundNumber() {
		return board.getRoundNumber();
	}

	@Override
	public String toString() {
		return "HistoricBoard [board=" + board + "]";
	}

	@Override
	public void stopGame() {
		throw new UnsupportedOperationException("Tried to change history");
	}

	@Override
	public int getSize() {
		return board.getSize();
	}

	@Override
	public Color getNextColor() {
		throw new UnsupportedOperationException("No next color");
	}

	@Override
	public int getScore(Color positiveColor) {
		return board.getScore(positiveColor);
	}
	
	

}
